<template>
  <div>
    <el-form :inline="true">
      <el-form-item>
        <el-button type="primary" @click.native="dialogVisible = true">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%;margin-bottom: 20px;" row-key="id" border default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column prop="name" label="名称" sortable width="180">
      </el-table-column>
      <el-table-column prop="perms" label="权限编码" sortable width="180">
      </el-table-column>
      <el-table-column prop="icon" label="图标">
      </el-table-column>
      <el-table-column prop="type" label="类型">
        <template slot-scope="scope">
          <el-tag size="small" v-if="scope.row.type === 0">目录</el-tag>
          <el-tag size="small" v-else-if="scope.row.type === 1" type="success">菜单</el-tag>
          <el-tag size="small" v-else-if="scope.row.type === 2" type="info">按钮</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="path" label="菜单URL" sortable width="180">
      </el-table-column>
      <el-table-column prop="component" label="菜单组件" sortable width="180">
      </el-table-column>
      <el-table-column prop="orderNum" label="排序号">
      </el-table-column>
      <el-table-column prop="statue" label="状态">
        <template slot-scope="scope">
          <el-tag size="small" v-if="scope.row.statue === 1" type="success">正常</el-tag>
          <el-tag size="small" v-else-if="scope.row.statue === 0" type="danger">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="operation" label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click.native="dialogVisible = true">编辑</el-button>
          <el-divider direction="vertical"></el-divider>
          <el-button type="text">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="提示" :visible.sync="dialogVisible" width="600px" :before-close="handleClose">
      <el-form :model="editForm" :rules="rules" ref="editForm" label-width="100px" class="demo-ruleForm">

        <el-form-item label="上级菜单" prop="parentId">
          <el-select v-model="editForm.parentId" placeholder="请选择上级菜单">
            <template v-for="item in tableData">
              <el-option :label="item.name" :key="item.name" :value="item.id"></el-option>
              <template v-for="child in item.children">
                <el-option :label="child.name" :key="child.name" :value="child.id">
                  <span>{{ "- " + child.name }}</span>
                </el-option>
              </template>
            </template>
          </el-select>
        </el-form-item>

        <el-form-item label="活动名称" prop="name">
          <el-input v-model="editForm.name"></el-input>
        </el-form-item>

        <el-form-item label="特殊资源" prop="resource">
          <el-radio-group v-model="editForm.resource">
            <el-radio label="线上品牌商赞助"></el-radio>
            <el-radio label="线下场地免费"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('editForm')">立即创建</el-button>
          <el-button @click="resetForm('editForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>
<script>
export default {
  name: 'Menu',
  data () {
    return {
      dialogVisible: false,
      editForm: {
        name: '',
        parentId: '',
        resource: ''
      },
      rules: {
        name: [{
          required: true,
          message: '请输入活动名称',
          trigger: 'blur'
        },
        {
          min: 3,
          max: 5,
          message: '长度在 3 到 5 个字符',
          trigger: 'blur'
        }
        ],
        parentId: [{
          required: true,
          message: '请选择活动区域',
          trigger: 'change'
        }],
        resource: [{
          required: true,
          message: '请选择活动资源',
          trigger: 'change'
        }]
      },
      tableData: [{
        id: 1,
        date: '2016-05-02',
        name: '王小虎1',
        type: 0,
        address: '上海市普陀区金沙江路 1518 弄',
        statue: 0
      },
      {
        id: 2,
        date: '2016-05-04',
        name: '王小虎2',
        type: 0,
        statue: 0,
        address: '上海市普陀区金沙江路 1517 弄'
      },
      {
        id: 3,
        date: '2016-05-01',
        name: '王小虎3',
        type: 0,
        statue: 1,
        address: '上海市普陀区金沙江路 1519 弄',
        children: [{
          id: 31,
          date: '2016-05-01',
          name: '王小虎3-1',
          type: 1,
          statue: 1,
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          id: 32,
          date: '2016-05-01',
          name: '王小虎3-2',
          type: 1,
          statue: 1,
          address: '上海市普陀区金沙江路 1519 弄'
        }]
      },
      {
        id: 4,
        date: '2016-05-03',
        name: '王小虎4',
        statue: 1,
        type: 0,
        address: '上海市普陀区金沙江路 1516 弄'
      }
      ]
    }
  },
  methods: {
    handleClose (done) {
      this.dialogVisible = false
      // this.$confirm('确认关闭？')
      //   .then(_ => {
      //     done()
      //   })
      //   .catch(_ => {})
    }
  }
}

</script>
<style scoped>

</style>
